package com.platform.usercenter.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//import com.platform.common.log.annotation.Log;
//import com.platform.common.log.enums.BusinessType;
import com.platform.common.security.annotation.RequiresPermissions;
import com.platform.usercenter.domain.SysAppPermission;
import com.platform.usercenter.service.ISysAppPermissionService;
import com.platform.common.core.web.controller.BaseController;
import com.platform.common.core.web.domain.AjaxResult;
import com.platform.common.core.utils.poi.ExcelUtil;
import com.platform.common.core.web.page.TableDataInfo;

/**
 * 应用数据权限关系Controller
 *
 * @author platform
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/appPermission")
public class SysAppPermissionController extends BaseController
{
    @Resource
    private ISysAppPermissionService sysAppPermissionService;

    /**
     * 查询应用数据权限关系列表
     */
    @RequiresPermissions("usercenter:appPermission:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAppPermission sysAppPermission)
    {
        startPage();
        List<SysAppPermission> list = sysAppPermissionService.selectSysAppPermissionList(sysAppPermission);
        return getDataTable(list);
    }

    /**
     * 导出应用数据权限关系列表
     */
    @RequiresPermissions("usercenter:appPermission:export")
    //@Log(title = "应用数据权限关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppPermission sysAppPermission)
    {
        List<SysAppPermission> list = sysAppPermissionService.selectSysAppPermissionList(sysAppPermission);
        ExcelUtil<SysAppPermission> util = new ExcelUtil<SysAppPermission>(SysAppPermission.class);
        util.exportExcel(response, list, "应用数据权限关系数据");
    }

    /**
     * 获取应用数据权限关系详细信息
     */
    @RequiresPermissions("usercenter:appPermission:query")
    @GetMapping(value = "/{permissionId}")
    public AjaxResult getInfo(@PathVariable("permissionId") Long permissionId)
    {
        return success(sysAppPermissionService.selectSysAppPermissionByPermissionId(permissionId));
    }

    /**
     * 新增应用数据权限关系
     */
    @RequiresPermissions("usercenter:appPermission:add")
    //@Log(title = "应用数据权限关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAppPermission sysAppPermission)
    {
        return toAjax(sysAppPermissionService.insertSysAppPermission(sysAppPermission));
    }

    /**
     * 修改应用数据权限关系
     */
    @RequiresPermissions("usercenter:appPermission:edit")
    //@Log(title = "应用数据权限关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAppPermission sysAppPermission)
    {
        return toAjax(sysAppPermissionService.updateSysAppPermission(sysAppPermission));
    }

    /**
     * 删除应用数据权限关系
     */
    @RequiresPermissions("usercenter:appPermission:remove")
    //@Log(title = "应用数据权限关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{permissionIds}")
    public AjaxResult remove(@PathVariable Long[] permissionIds)
    {
        return toAjax(sysAppPermissionService.deleteSysAppPermissionByPermissionIds(permissionIds));
    }
}
